package com.atguigu.srb.core.service.impl;

import com.atguigu.srb.core.pojo.entity.BorrowerAttach;
import com.atguigu.srb.core.mapper.BorrowerAttachMapper;
import com.atguigu.srb.core.pojo.vo.BorrowerAttachVO;
import com.atguigu.srb.core.service.BorrowerAttachService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import java.util.ArrayList;
import java.util.List;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 借款人上传资源表 服务实现类
 * </p>
 *
 * @author lupengning
 * @since 2021-05-27
 */
@Service
public class BorrowerAttachServiceImpl extends ServiceImpl<BorrowerAttachMapper, BorrowerAttach> implements BorrowerAttachService {

  @Override
  public List<BorrowerAttachVO> selectBorrowerAttachVOList(Long borrowerId) {

    LambdaQueryWrapper<BorrowerAttach> queryWrapper = new LambdaQueryWrapper<>();
    List<BorrowerAttach> borrowerAttachList = baseMapper
        .selectList(queryWrapper.eq(BorrowerAttach::getBorrowerId, borrowerId));

    List<BorrowerAttachVO> borrowerAttachVOList = new ArrayList<>();
    borrowerAttachList.forEach(borrowerAttach -> {
      BorrowerAttachVO borrowerAttachVO = new BorrowerAttachVO();
      borrowerAttachVO.setImageType(borrowerAttach.getImageType());
      borrowerAttachVO.setImageUrl(borrowerAttach.getImageUrl());

      borrowerAttachVOList.add(borrowerAttachVO);
    });
    return borrowerAttachVOList;
  }
}
